#!/bin/bash
# 启动 Flink Agents 本地模式

set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"

echo "🔄 切换到 Flink Agents 本地模式..."
echo "=================================================="

# 切换到项目根目录
cd "$PROJECT_ROOT"

# 停止其他处理器
echo "🛑 停止其他处理器..."
docker-compose -f docker/docker-compose.yml stop event-processor flink-cluster-processor 2>/dev/null || true

# 启动 Flink Agents 本地模式
echo "🚀 启动 Flink Agents (本地模式)..."
docker-compose -f docker/docker-compose.yml --env-file .env --profile flink-local up -d

# 等待服务启动
echo "⏳ 等待服务启动（5秒）..."
sleep 5

# 检查服务状态
echo ""
echo "📊 服务状态："
echo "=================================================="
docker ps --filter "name=browse-etl" --format "table {{.Names}}\t{{.Status}}" | grep -E "flink|postgres|localstack"

echo ""
echo "=================================================="
echo "✅ Flink Agents 本地模式已启动"
echo ""
# 记录当前模式
echo "flink-local" > /tmp/browse-etl-mode
echo "📝 快捷命令："
echo "   部署Lambda: make deploy"
echo "   运行测试: make test"
echo "   查看 Flink UI: make flink-ui (http://localhost:8081)"
echo "   切换模式: make start / make start-flink-cluster"
echo "   查看日志: make logs-flink-local"
echo "=================================================="

